calculate time complexity